import type { App } from "vue";
import { createRouter, createWebHashHistory } from "vue-router";

import { transformRouteToVue } from '@/utils';
import { constroutes } from "./routes";
import { createRouterGuard } from "./guard";
import { transformRouteNameToRoutePath } from '@/utils';

export const router = createRouter({
  history: createWebHashHistory(),
  routes: transformRouteToVue(constroutes)
});

export async function setupRouter(app: App) {
  app.use(router);
  createRouterGuard(router);
  await router.isReady();
}

/** 路由名称 */
export const routeName = (key: AuthRoute.RouteKey) => key;

/** 路由路径 */
export const routePath = (key: Exclude<AuthRoute.RouteKey, 'not-found-page'>) => transformRouteNameToRoutePath(key);
